package com.sense.common.lang;

import com.sense.common.consts.HttpConstants;
import lombok.Data;

import java.io.Serializable;

@Data
public class RestfulResponse implements Serializable {


    private Integer code;


    private String message;


    private Object data;


    private RestfulResponse(){}


    public static RestfulResponse of(Object data){
        RestfulResponse response = new RestfulResponse();
        response.code = HttpConstants.SUCCESS_CODE;
        response.message = HttpConstants.SUCCESSFUL_MESSAGE;
        response.data = data;
        return response;
    }


    public static RestfulResponse fail(Integer code, String message){
        RestfulResponse response = new RestfulResponse();
        response.code = code;
        response.message = message;
        return response;
    }


    //public static RestfulResponse fail(ResponseBaseEnums responseBaseEnums) {
    //    RestfulResponse response = new RestfulResponse();
    //    response.code = responseBaseEnums.getCode();
    //    response.message = responseBaseEnums.getMessage();
    //    return response;
    //}


    public static RestfulResponse fail(String message){
        RestfulResponse response = new RestfulResponse();
        response.code = HttpConstants.ERROR_CODE;
        response.message = message;
        return response;
    }


    public static RestfulResponse fail(){
        RestfulResponse response = new RestfulResponse();
        response.code = HttpConstants.ERROR_CODE;
        response.message = HttpConstants.FAILED_MESSAGE;
        return response;
    }


}